﻿using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using Microsoft.Commerce.Proxy.TransactionService.v201001;
using System;

namespace TestWebApplication.CommerceTransaction.APIs
{
    public class CommerceTransactionRefundPurchaseApi : CommerceTransactionApi
    {
        private RefundPurchaseInput input;
        public RefundPurchaseOutput output;

        private CallerInfo callerInfo;
        private string[] idSet;
        private bool isImmediate;
        private PaymentMethod paymentMethod;
        private Property[] propertyBag;
        private string purchaseId;
        private string refundAmount;
        private RefundPurchaseContext refundPurchaseContext;
        private string refundType;
        private bool revertProductFlag;

        public CommerceTransactionRefundPurchaseApi(BasicHttpBinding binding, EndpointAddress address, X509Certificate2 clientCert,
               CallerInfo callerInfo, PaymentMethod paymentMethod, string purchaseId, string refundAmount)
            : base(binding, address, clientCert)
        {

            this.callerInfo = callerInfo;
            this.paymentMethod = paymentMethod;
            this.purchaseId = purchaseId;
            this.refundAmount = refundAmount;
        }

        protected override AbstractResponse ExecuteInternal(TransactionServiceChannel channel)
        {
            this.output = channel.RefundPurchase(input);

            return output;
        }

        public override void PrepareRequestData()
        {
            // prepare the create account input;
            this.input = new RefundPurchaseInput()
            {
                APIContext = new APIContext()
                {
                    TrackingGuid = this.trackingGuid,
                },
                CallerInfo = this.callerInfo,
                PaymentMethod = this.paymentMethod,
                PurchaseId = this.purchaseId,
                RefundAmount = this.refundAmount,
                RefundType = "RefundFullPurchase",
                RefundPurchaseContext = new RefundPurchaseContext()
                {
                    TimeStamp = DateTime.Now,
                },
                IsImmediate = false,
                RevertProductFlag = false,
            };
        }

        public override void PrepareResponseData()
        {


            return;
        }
    }
}
